package com.neoyr.meeting.common;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice(annotations = {RestController.class, Controller.class, Service.class})
@ResponseBody
public class GlopbalExceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public Result<String> exception(SQLIntegrityConstraintViolationException ex) {
        return Result.failed(ex.toString());
    }

    @ExceptionHandler(CustomException.class)
    public Result<String> Custom(CustomException ex) {
        return Result.failed(ex.getMessage());
    }
}
